<template>
  <div class="suggest">
    <ul class="suggest-list">
      <li class="item" v-for="item in suggest" @click="searcItem(item)">
        <span class="van-hairline--bottom">{{item}}</span>
      </li>
    </ul>
  </div>
</template>

<script>
import axios from "axios";
import { searchSuggest } from "../../../api/getDatas";
export default {
  props: {
    query: {
      type: String,
      default: null
    }
  },
  data() {
    return {
      suggest: null
    };
  },
  methods: {
    searcItem(item) {
      this.$router.push({
        path: "/search_result",
        query: {
          search_key: item
        }
      });
    },
    initData() {
      searchSuggest(this.query).then(res => {
        this.suggest = res.data.suggest;
      });
    }
  },
  created() {
    this.initData();
  },
  watch: {
    query(val) {
      this.initData();
    }
  }
};
</script>

<style lang="less" scoped>
.suggest {
  background-color: white;
  position: fixed;
  top: 44px;
  left: 0;
  right: 0;
  bottom: 0;
  .item {
    width: 100%;
    height: 0.46rem;
    padding-left: 0.12rem;
    span {
      display: flex;
      height: 100%;
      align-items: center;
    }
  }
}
</style>

